package com.platform.modules.report.controller;

import com.platform.common.utils.DateUtils;
import com.platform.common.utils.MapUtil;
import com.platform.modules.report.dao.QlyAccReportDao;
import com.platform.modules.report.dto.BaseItemDTO;
import com.platform.modules.report.dto.BaseQueryDTO;
import com.platform.modules.report.dto.QlyAccTypeDTO;
import com.platform.modules.report.service.QlyAccReportService;
import com.platform.modules.sys.entity.SysDictEntity;
import com.platform.modules.sys.service.SysDictService;
import com.platform.web.utils.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

@SuppressWarnings("ALL")
@Api(tags = "报表 - 质量验收分析")
@RestController
@RequestMapping("report/qly/acc")
public class QlyAccReportController extends BaseReportController {

    @Autowired
    QlyAccReportService qlyAccReportService;
    @Autowired
    SysDictService sysDictService;


    @ApiOperation("今日验收数据 - 验收数q")
    @PostMapping("today")
    public CommonResult<Map<String, Object>> today(){
        Integer count = qlyAccReportService.qlyAccCount(MapUtil.of("date", DateUtils.format(new Date())));
        return CommonResult.success(MapUtil.of("qlyAccCount",count));
    }


    @ApiOperation("验收类型统计 - 默认:柱图")
    @PostMapping("qlyAccCountGroupByYear")
    public CommonResult<List<BaseItemDTO>> qlyAccCountGroupByYear(@RequestBody BaseQueryDTO baseQueryDTO){
        Map<String,Object> map = qlyAccReportService.qlyAccCountGroupByYear(baseQueryDTO);
        List<BaseItemDTO> data = this.buildStringItem(map, baseQueryDTO.getYearList());
        return CommonResult.success(data);
    }


    @ApiOperation("项目类型验收统计 - 默认:饼")
    @PostMapping("qlyAccCountGroupByPrjCategory")
    public CommonResult<List<BaseItemDTO>> qlyAccCountGroupByPrjCategory(@RequestBody BaseQueryDTO baseQueryDTO){
        Map<String,Object> map = qlyAccReportService.qlyAccCountGroupByPrjCategory(baseQueryDTO);
        List<SysDictEntity> dicts = sysDictService.queryByCode(MapUtil.of("code","PRJ_CATEGORY"));
        List<BaseItemDTO> data = this.buildDictItem(map,dicts);
        return CommonResult.success(data);
    }




    @ApiOperation("验收类型统计 - 默认:柱图")
    @PostMapping("qlyAccCountGroupByType")
    public CommonResult<List<BaseItemDTO>> qlyAccCountGroupByType(@RequestBody BaseQueryDTO baseQueryDTO){
        Map<String,Object> qlyAccCountMap = qlyAccReportService.qlyAccCountGroupByType(baseQueryDTO);
        List<BaseItemDTO> data = Arrays.asList(
                new BaseItemDTO("地基",qlyAccCountMap.getOrDefault("1",0),"1"),
                new BaseItemDTO("防水",qlyAccCountMap.getOrDefault("2",0),"2"),
                new BaseItemDTO("钢筋隐蔽",qlyAccCountMap.getOrDefault("3",0),"3"),
                new BaseItemDTO("混凝土",qlyAccCountMap.getOrDefault("4",0),"4"),
                new BaseItemDTO("屋面",qlyAccCountMap.getOrDefault("5",0),"5"),
                new BaseItemDTO("其他",qlyAccCountMap.getOrDefault("6",0),"6")
        );
        return CommonResult.success(data);
    }

    @ApiOperation("各市质量验收类型综合统计排名 - 默认:表格")
    @PostMapping("cityRanking")
    public CommonResult<List<QlyAccTypeDTO>> cityRanking(){
        List<QlyAccTypeDTO> list = Arrays.asList(
                new QlyAccTypeDTO("130100","石家庄",999,999,999,999,999,999,999),
                new QlyAccTypeDTO("130200","唐山",888,999,888,888,888,888,888),
                new QlyAccTypeDTO("130300","秦皇岛",888,999,888,888,888,888,888),
                new QlyAccTypeDTO("130400","邯郸",888,999,888,888,888,888,888),
                new QlyAccTypeDTO("130500","邢台",888,999,888,888,888,888,888),
                new QlyAccTypeDTO("130600","保定",888,999,888,888,888,888,888),
                new QlyAccTypeDTO("130700","张家口",888,999,888,888,888,888,888),
                new QlyAccTypeDTO("130800","承德",888,999,888,888,888,888,888),
                new QlyAccTypeDTO("130700","张家口",888,999,888,888,888,888,888),
                new QlyAccTypeDTO("130800","承德",888,999,888,888,888,888,888),
                new QlyAccTypeDTO("130700","张家口",888,999,888,888,888,888,888)
        );
        return CommonResult.success(list);
    }



}
